package cn.edu.sjtu.se.dslab.component.aadl;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import cn.edu.sjtu.se.dslab.auth.User;
import cn.edu.sjtu.se.dslab.project.Project;
/**
 * 数据库中的aadl存储结构
 * @author sunke
 *
 */

@Entity
@Table(name = "aadl_model")
public class AADLModel implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 885452832086613558L;

	private long id;

	private String aadlPath;

	private String xmlPath;
	
	private String aaxlPath;
	
	private String uri;
	
	private Project project; 

	private User owner;
	
	private Set<AADLLoger> logers;
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	@Column(name = "aadl_path", nullable = false, length = 255)
	public String getAadlPath() {
		return aadlPath;
	}

	public void setAadlPath(String aadlPath) {
		this.aadlPath = aadlPath;
	}

	@Column(name = "xml_path", nullable = false, length = 255)
	public String getXmlPath() {
		return xmlPath;
	}

	public void setXmlPath(String xmlPath) {
		this.xmlPath = xmlPath;
	}
	
	@Column(name = "aaxl_path", nullable = true, length = 255)
	public String getAaxlPath() {
		return aaxlPath;
	}

	public void setAaxlPath(String aaxlPath) {
		this.aaxlPath = aaxlPath;
	}

	@Column(name = "uri", nullable = false, length = 255)
	public String getUri() {
		return uri;
	}

	public void setUri(String uri) {
		this.uri = uri;
	}
	
	@OneToOne(cascade = { CascadeType.REFRESH })
	@JoinColumn(name = "project_id",nullable = true)
	public Project getProject() {
		return project;
	}

	public void setProject(Project project) {
		this.project = project;
	}
	
	@ManyToOne(cascade = { CascadeType.REFRESH})
	@JoinColumn(name = "owner_id")
	public User getOwner() {
		return owner;
	}

	public void setOwner(User owner) {
		this.owner = owner;
	}
	
	@OneToMany(cascade = { CascadeType.ALL }, mappedBy = "model", fetch = FetchType.EAGER)
	public Set<AADLLoger> getLogers() {
		return logers;
	}

	public void setLogers(Set<AADLLoger> logers) {
		this.logers = logers;
	}
	
}
